#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> degree(n, 0);
    unordered_map<int, vector<int>> graph;
    while (m--)
    {
        int s, t;
        cin >> s >> t;
        degree[t]++;
        graph[s].push_back(t);
    }
    vector<int> result;
    queue<int> que;
    for (int i = 0; i < n; i++)
    {
        if (degree[i] == 0)
        {
            que.push(i);
        }
    }
    while (!que.empty())
    {
        int index = que.front();
        que.pop();
        result.push_back(index);
        for (auto x : graph[index])
        {
            degree[x]--;
            if (degree[x] == 0)
            {
                que.push(x);
            }
        }
    }
    if ((int)result.size() == n)
    {
        for (int i = 0; i < n - 1; i++)
        {
            cout << result[i] << " ";
        }
        cout << result[n - 1] << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}